package great.project.service.test.tranal;

import great.project.mapper.Test1Mapper;
import great.project.pojo.entity.Test1;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class Transaction1Service {

    @Resource
    private Test1Mapper test1Mapper;

    @Transactional(rollbackFor = Exception.class)
    public void testPrivate(int isThrow) {
        if (isThrow > 0) {
            throw new RuntimeException("1");
        }
        test1Mapper.insert(Test1.builder().id(2).name("" + isThrow).build());

    }

    @Transactional(rollbackFor = Exception.class)
    public void testPublic(int isThrow) {
        if (isThrow > 0) {
            throw new RuntimeException("2");
        }
        test1Mapper.insert(Test1.builder().id(3).name("" + isThrow).build());

    }

}
